package com.zhenyi.dingke.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.jfinal.kit.PropKit;
import com.utils.AuthUtils;

import cn.hutool.core.text.StrFormatter;

public class DKAppAuthInterceptor implements Interceptor {

	private final String APP_ID = PropKit.get("PXLM_APP_ID");
	// private final String APP_SECRET = PropKit.get("PXLM_APP_SECRET");

	@Override
	public void intercept(Invocation inv) {
		Controller controller = inv.getController();
		String url = "https://open.weixin.qq.com/connect/oauth2/authorize?"
				+ "appid={}&redirect_uri={}&response_type=code&scope={}&state={}#wechat_redirec";
		String redirect = "http://app.cenjiawen.com/dk/app/wechat";
		url = StrFormatter.format(url, APP_ID, redirect, "snsapi_base", "");
		if (!AuthUtils.verify(controller)) {
			controller.redirect(url);
			return;
		}
		// String signupUrl = "/dk/app/signup";
		// String uid = AuthUtils.getTokenUid(controller);
		// DkUser user = DkUser.dao.findById(uid);
		// if (StrKit.isBlank(user.getMobile())) {
		// controller.redirect(signupUrl);
		// return;
		// }
		// if (StrKit.isBlank(user.getName())) {
		// controller.redirect(signupUrl);
		// return;
		// }
		inv.invoke();
	}

}
